package com.yangye.otherdemo.proxy.jdkdynamic;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class JdkDynamicProxy {

	public static void main(String[] args) {
		Class<Hello> clazz = Hello.class;
		Hello hello = (Hello) Proxy.newProxyInstance(clazz.getClassLoader(), new Class[]{clazz}, new InvocationHandler() {
			@Override
			public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
				if (method.getName().equals("sayHello")) {
					System.out.println("Good morning, " + args[0]);
				}
				return proxy;
			}
		});
		hello.sayHello("zaozao");
	}
}
